﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;

namespace Webbshop.Account
{
    public partial class Register : BasePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
        }

        protected void RegisterUser_CreatedUser(object sender, EventArgs e)
        {
            RegisterProfile(); // Register Profile Properties

            FormsAuthentication.SetAuthCookie(RegisterUser.UserName, false /* createPersistentCookie */);

            string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            if (String.IsNullOrEmpty(continueUrl))
            {
                continueUrl = "~/";
            }
            Response.Redirect(continueUrl);
        }

        /// <summary>
        /// Register additional data into the Profile
        /// </summary>
        protected void RegisterProfile()
        {
            MyProfile p = ProfileBase.Create(RegisterUser.UserName) as MyProfile;

            p.FirstName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("FirstName")).Text;
            p.LastName = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("LastName")).Text;
            p.Street = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Street")).Text;
            p.PostalCode = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("PostalCode")).Text;
            p.PostalArea = ((TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("PostalArea")).Text;

            p.Save();
        }

    }
}
